//
//  MineViewController.m
//  Gunz
//
//  Created by Joggy on 15/12/12.
//  Copyright © 2015年 NUPT. All rights reserved.
//

#import "MineViewController.h"
#import "MCompletedTaskViewController.h"
#import "MExecutingViewController.h"
#import "MSignupViewController.h"
#import "MMReleaseViewController.h"
#import "MDataViewController.h"
//#import "STableViewCell2.h"

@implementation MineViewController

-(void)viewDidLoad{
    [super viewDidLoad];
    [self prepareForNav];
    [self prepareForLayout];
//    testTitles = [[NSArray alloc] initWithObjects:@"已完成的任务", @"正在执行的任务", @"已报名的任务", @"我发布的任务", @"我的活动", nil];
    teskIcons = @[
                   @[@"阿狸"],
                   @[@"01_yiwanchengde", @"02_zhengzaizhixing", @"03_yibaomingde", @"04_wofabude", @"06_guanyuwomen"],
                   @[@"05_xitongtuijian"],
                   @[@"06_wodehuodong"],
                   ];
    teskTitles = @[
                   @[@""],
                   @[@"已完成的任务", @"正在执行的任务", @"已报名的任务", @"我发布的任务", @"我的数据"],
                   @[@"系统推荐任务"],
                   @[@"我的活动"],
                   ];
    pushToTeskView = @[[[MCompletedTaskViewController alloc] init], [[MExecutingViewController alloc] init], [[MSignupViewController alloc] init], [[MMReleaseViewController alloc] init], [[MDataViewController alloc] init]];
}

-(void)prepareForNav{
    [super prepareForNav];
    self.title = @"我的";
}

-(void)prepareForLayout {
    [super prepareForLayout];
    tb = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight - 64) style:UITableViewStylePlain];
    tb.delegate = self;
    tb.dataSource = self;
    tb.backgroundColor = [UIColor clearColor];
    tb.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 10)];
    tb.showsVerticalScrollIndicator = false;
    tb.separatorStyle = UITableViewCellSelectionStyleBlue;
    tb.separatorColor = [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1];
    [tb registerClass:[UITableViewCell class] forCellReuseIdentifier:@"MCell1"];
    [self.view addSubview:tb];
}

#pragma 代理方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    if(indexPath.section == 0) {
        MVMyInfoViewController *myInfo = [[MVMyInfoViewController alloc] init];
        myInfo.hidesBottomBarWhenPushed = true;
        [[self navigationController] pushViewController:myInfo animated:true];
    }
    else if(indexPath.section == 1) {
        UIViewController *viewCon = pushToTeskView[indexPath.row];
        viewCon.hidesBottomBarWhenPushed = true;
        [[self navigationController] pushViewController:viewCon animated:true];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.section == 0) {
        return 88;
    }
    else {
        return 47;
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *arr = teskTitles[section];
    return arr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 20;
}

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 20)];
    v.backgroundColor = [UIColor clearColor];
    return v;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MCell1"];
    cell.backgroundColor = [UIColor colorWithRed:0.9765 green:0.9765 blue:0.9843 alpha:1];
    UIImageView *arrowheadView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 11, 18)];
    arrowheadView.image = [UIImage imageNamed:@"all_arrow"];
    if(indexPath.section == 0) {
        userIcon = [[MVUserIcon alloc] init];
        [cell.contentView addSubview:userIcon];
        arrowheadView.layer.position = CGPointMake(screenWidth - 15 - 9, 44);
    }
    else {
        NSArray *arr = teskIcons[indexPath.section];
        cell.imageView.image = [UIImage imageNamed:arr[indexPath.row]];
        NSArray *arr1 = teskTitles[indexPath.section];
        cell.textLabel.text = arr1[indexPath.row];
        cell.textLabel.textColor = [UIColor colorWithRed:0.298 green:0.345 blue:0.4235 alpha:1];
        arrowheadView.layer.position = CGPointMake(screenWidth - 15 - 9, 47/2);
    }
    [cell.contentView addSubview:arrowheadView];
    return cell;
}

@end
